package light.head.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Formula;
/**
 * 物品类型表
 *
 */
@Entity
@Table
public class GoodsType implements Serializable {

	
	private static final long serialVersionUID = 1956947603615196038L;
	
	
	private Integer code;
	private String name;					//类型名称
	private Integer pc;						//父类型
	private Integer cu;						//创建人编号
	private Date ct;						//创建时间
	private Integer oc;						//机构编号
	
	private String cn;						//创建人名称
	private String on;						//机构名称
	private String pname;					//父类型名称
	private Integer sonCount;						// 下级类型总数
	private List<GoodsType> sonList;			// 子类别列表
	private Boolean deleted;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column
	public Integer getCode() {
		return code;
	}
	@Column(length= 20)
	public String getName() {
		return name;
	}
	@Column
	public Boolean getDeleted() {
		return deleted;
	}
	@Column
	public Integer getPc() {
		return pc;
	}
	@Column
	public Integer getCu() {
		return cu;
	}
	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable = false, nullable = false)
	public Date getCt() {
		return ct;
	}
	@Column
	public Integer getOc() {
		return oc;
	}
	@Formula("(SELECT u.realName FROM UserInfo u WHERE u.code = cu )")
	public String getCn() {
		return cn;
	}
	@Formula("(SELECT o.name FROM Organ o WHERE o.code = oc )")
	public String getOn() {
		return on;
	}
	@Formula("(SELECT gt.name FROM GoodsType gt WHERE gt.code = pc )")
	public String getPname() {
		return pname;
	}
	@Transient
	public List<GoodsType> getSonList() {
		return sonList;
	}
	@Formula("(SELECT COUNT(*) FROM GoodsType gt WHERE (gt.deleted = 0 OR gt.deleted IS NULL) AND gt.pc = code)")
	public Integer getSonCount() {
		return sonCount;
	}
	
	
	
	
	
	public void setSonList(List<GoodsType> sonList) {
		this.sonList = sonList;
	}
	public void setPc(Integer pc) {
		this.pc = pc;
	}
	public void setCu(Integer cu) {
		this.cu = cu;
	}
	public void setCt(Date ct) {
		this.ct = ct;
	}
	public void setOc(Integer oc) {
		this.oc = oc;
	}
	public void setCn(String cn) {
		this.cn = cn;
	}
	public void setOn(String on) {
		this.on = on;
	}
	public void setPname(String pname) {
		this.pname = pname;
	}
	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setSonCount(Integer sonCount) {
		this.sonCount = sonCount;
	}
	
}
